package com.second.client.controller;

import com.second.client.pojo.entity.ClientCoupon;
import com.second.client.pojo.vo.CouponQueryVo;
import com.second.client.pojo.vo.PageVo;
import com.second.client.service.ClientCouponService;
import com.second.common.pojo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (ClientCoupon)表控制层
 *
 * @author lvyongqi
 * @since 2021-07-25 09:31:09
 */
@RestController
@RequestMapping("coupon")
@Api(tags = "优惠券控制层")
public class ClientCouponController {

    /**
     * 服务对象
     */
    @Resource
    private ClientCouponService clientCouponService;

    /**
     * 查询所有的优惠券信息
     * @param pageVo 分页工具类
     * @param couponQueryVo 模糊查询工具类
     * @return 所有数据
     */
    @PostMapping("getAllCoupon")
    @ApiOperation(value = "查询所有的优惠券信息")
    public R getAllCoupon(PageVo pageVo, CouponQueryVo couponQueryVo) {
        return clientCouponService.getAllCoupon(pageVo,couponQueryVo);
    }

    /**
     * 根据id删除优惠券
     * @param couponId 优惠券Id
     * @return 删除结果
     */
    @DeleteMapping("deleteCouponById")
    @ApiOperation(value = "根据id删除优惠券")
    public R deleteCouponById(Integer couponId) {
        return clientCouponService.deleteCouponById(couponId);
    }

    /**
     * 修改/添加优惠券信息
     * @param clientCoupon  优惠券信息
     * @return  修改结果
     */
    @PutMapping("updateCoupon")
    @ApiOperation(value = "修改/添加优惠券信息")
    public R updateCoupon(ClientCoupon clientCoupon) {
        return clientCouponService.updateCoupon(clientCoupon);
    }

    /**
     * 根据id查询优惠券的优惠金额
     * @param couponId  优惠券id
     * @return  优惠金额
     */
    @GetMapping("getCouponAmountById")
    @ApiOperation(value = "根据id查询优惠券的优惠金额")
    @ApiImplicitParam(name = "couponId",value = "优惠券id")
    public Integer getCouponAmountById(Integer couponId) {
        return clientCouponService.getCouponAmountById(couponId);
    }
}
